''' <summary>
''' This is a game component that implements IUpdateable.
''' </summary>
Public Class GameCamera
    Inherits Microsoft.Xna.Framework.GameComponent
    Protected mView As Matrix
    Protected mProjection As Matrix
    Private mLookAt As Vector3
    Private mPosition As Vector3
    Private mViewField As Single
    Private mViewNear As Single
    Private mViewFar As Single

    Public ReadOnly Property Projection As Matrix
        Get
            Return mProjection
        End Get
    End Property
    Public ReadOnly Property View As Matrix
        Get
            Return mView
        End Get
    End Property

    Public Property ViewField As Single
        Get
            Return mViewField
        End Get
        Set(value As Single)
            mViewField = value
            SetProjection()
        End Set
    End Property
    Public Property ViewNear As Single
        Get
            Return mViewNear
        End Get
        Set(value As Single)
            mViewNear = value
            SetProjection()
        End Set
    End Property
    Public Property ViewFar As Single
        Get
            Return mViewFar
        End Get
        Set(value As Single)
            mViewFar = value
            SetProjection()
        End Set
    End Property

    Public Property LookAt As Vector3
        Set(value As Vector3)
            mLookAt = value
            SetCamera()
        End Set
        Get
            Return mLookAt
        End Get
    End Property
    Public Property Position As Vector3
        Set(value As Vector3)
            mPosition = value
            SetCamera()
        End Set
        Get
            Return mPosition
        End Get
    End Property

    Private Sub SetCamera()
        mView = Matrix.CreateLookAt(mPosition, mLookAt, Vector3.Up)
    End Sub
    Private Sub SetProjection()
        mProjection = Matrix.CreatePerspectiveFieldOfView(mViewField, Game.GraphicsDevice.Viewport.AspectRatio, mViewNear, mViewFar)
    End Sub
    Public Sub New(ByVal game As Game)
        MyBase.New(game)
        ' TODO: Construct any child components here
        mPosition = New Vector3(0, 1, 0)
        mLookAt = New Vector3(0, 0, 16)
        mViewFar = 100
        mViewNear = 1
        mViewField = MathHelper.Pi / 3
        SetCamera()
        SetProjection()
    End Sub

    ''' <summary>
    ''' Allows the game component to perform any initialization it needs to before starting
    ''' to run.  This is where it can query for any required services and load content.
    ''' </summary>
    Public Overrides Sub Initialize()
        MyBase.Initialize()
    End Sub

    ''' <summary>
    ''' Allows the game component to update itself.
    ''' </summary>
    ''' <param name="gameTime">Provides a snapshot of timing values.</param>
    Public Overrides Sub Update(ByVal gameTime As GameTime)
        ' TODO: Add your update code here
        MyBase.Update(gameTime)
    End Sub

End Class
